<template>
  <div>
    <transition>
      <keep-alive>
        <router-view v-if="$route.meta.keepAlive"></router-view>
      </keep-alive>
    </transition>
    <transition>
      <router-view v-if="!$route.meta.keepAlive"></router-view>
    </transition>
    <!--<draggable @start="dragStart" @end="dragEnd">-->
      <!--<img id="kf" onclick="window.location.href='http://wodinghua.net/wap/static/custom/custom.html'" style="z-index: 98; width: 50px; height: 50px;position: fixed; left: 80%; top: 70%;" src="http://wodinghua.net/wap/static/images/kf.png"/>-->
    <!--</draggable>-->
    <!--<div id="kfChat" style="position: fixed; left: -2000px; top: 0; width: 100%; height: 100%; z-index: 1000; display: none">-->
      <!--<div id="kfChatCloseBtn" @click=switchShowKf(false) style="z-index: 19891015; position: fixed; top: 0; left: -2000px; background: #fff; width: 100%; height: 35px; line-height: 35px; padding-left: 10px;"><i class="iconfont icon-leftdot"></i>返回</div>-->
      <!--<iframe id="iframe1" style="width: 100%; height: 100%;" src="http://wodinghua.net/wap/static/custom/custom.html" frameborder="0"></iframe>-->
    <!--</div>-->
  </div>
</template>

<script>
  import draggable from 'vuedraggable'

  export default{
    data() {
      return {
        x: '',
        y: '',
        scrollTop: 0,
        tags: [],
        deviceType: this.$utils.getDeviceType(),
        memberInfo: this.$storage.getMemberInfo()
      }
    },
    created() {
    },
    components: {
      draggable: draggable
    },
    mounted() {
      let alerting = false
      window.setInterval(() => {
        if (alerting) {
          return
        } else {
          this.$request.getAppVersionInfo().then(data => {
            if (parseFloat(data.app_version) > parseFloat(this.$config.versionCode)) {
              alerting = true
              this.$messageBox.alert(data.version_remark, '新版本更新完成').then(() => {
                alerting = false
                console.log('is_refresh', data.is_refresh)
                if (data.is_refresh == '1') {
                  console.log('refresh')
                  window.localStorage.clear()
                  window.sessionStorage.clear()
                  this.$utils.delCookie('key')
                }
                window.location.reload(true)
              })
            }
          }).catch(e => {
          })
        }
      }, 5000)
      document.addEventListener('touchmove', this.$utils.throttle2(this.touchMoveFunc, 100), false)
      document.addEventListener('scroll', this.$utils.throttle2(this.scrollMoveFunc, 100), false)
      if (this.$utils.getDeviceType() == 'APICloud') {
        if (this.$config.localTest.open && this.memberInfo && this.memberInfo.member_id == this.$config.localTest.memberId) { // app连接本地服务测试
          if (this.$config.localTest.url.indexOf(window.location.hostname) == -1) {
            window.location.href = this.$config.localTest.url
          }
        }
      }
      let _this = this
      // window.apiready = function () { // APP才会执行，绑定推送
      if (this.deviceType == 'APICloud') {
        if (!_this.memberInfo || !_this.memberInfo.member_id) {
          return
        }
        // 将用户信息绑定到推送服务器
        var push = window.api.require('push')
        if (!push) {
          return
        }
        push.bind({
          userName: _this.memberInfo.member_name,
          userId: _this.memberInfo.member_id
        }, function (ret, err) {
          if (ret) {
            console.log(ret)
          } else {
            console.log(err)
          }
        })
      }
      // }
    },
    methods: {
      fixIosIframeWidthBug() { // ios iframe 宽度会撑开bug
        if (!navigator.userAgent.match(/iPad|iPhone/i)) {
          return false
        }
        var iframebody = document.getElementById('iframe1').contentWindow.document.body
        iframebody.style.width = document.body.clientWidth + 'px'
      },
      switchShowKf(value) {
        this.showKf = value
      },
      scrollMoveFunc() {
        this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop
      },
      touchMoveFunc(evt) {
        try {
          // evt.preventDefault() // 阻止触摸时浏览器的缩放、滚动条滚动等
          var touch = evt.touches[0] // 获取第一个触点
          this.x = Number(touch.pageX) // 页面触点X坐标
          this.y = Number(touch.pageY) // 页面触点Y坐标
        } catch (e) {
          console.log('touchMoveFunc：' + e.message)
        }
      },
      dragStart(data) {
//        document.getElementById('kf').style.display = 'none'
      },
      dragEnd(data) {
//        console.log(111)
//        document.getElementById('kf').style.display = 'block'
        document.getElementById('kf').style.top = (this.y - this.scrollTop - 25) + 'px'
        document.getElementById('kf').style.left = (this.x - 25) + 'px'
      }
    }
  }
</script>
<style>
  .mint-msgbox-btn.mint-msgbox-confirm, .mint-msgbox-btn.mint-msgbox-cancel {
    font-size: 16px;
    color: #f83166
  }

  .mint-msgbox-btn.mint-msgbox-confirm:active, .mint-msgbox-btn.mint-msgbox-cancel:active {
    color: #f83166
  }

  .mint-header {
    color: #f83166
  }

  .bg-white {
    background-color: #fff !important;
  }

  .bg-gray {
    background-color: #f5f5f5 !important;
  }
</style>